package com.Txunda.fxw.ui.toolkit.config;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;


import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.view.View;

import com.Txunda.fxw.base.utils.tool.AppManager;
import com.Txunda.fxw.base.utils.util.PreferencesUtils;


public class Config {
	/** ��¼״̬ */
	public static final String PREF_KEY_LOGIN_STATE = "PREF_KEY_LOGIN_STATE";

	public static final String PREF_KEY_CHECK_STATE = "PREF_KEY_CHECK_STATE";
	
	public static final String TYPE = "TYPE";

	public static View[] aty = new View[1];

	/** ���ӿ�URL */
	//public final static String BASE_URL = "http://fxw.txunda.com/index.php/Api/";
	public final static String BASE_URL = "http://www.yiyuanchazuo.com/index.php/Api/";
	
	public static List<Activity> list = new ArrayList<Activity>();

	/** �û��Ƿ��ѵ�¼ */
	public static boolean isLogin() {
		return PreferencesUtils.getBoolean(AppManager.getInstance().getTopActivity(), PREF_KEY_LOGIN_STATE);
	}

	public static boolean isCheck() {
		return PreferencesUtils.getBoolean(AppManager.getInstance().getTopActivity(), PREF_KEY_CHECK_STATE);
	}

	public static void AddAty(View view) {
		aty[0] = view;
	}

	/**
	 * ���õ�¼״̬
	 * 
	 * @param isLogin
	 *            ��¼-true δ��¼-false
	 */
	public static void setLoginState(boolean isLogin) {
		PreferencesUtils.putBoolean(AppManager.getInstance().getTopActivity(), PREF_KEY_LOGIN_STATE, isLogin);
	}

	public static void setCheckState(boolean isCheck) {
		PreferencesUtils.putBoolean(AppManager.getInstance().getTopActivity(), PREF_KEY_CHECK_STATE, isCheck);
	}

	/**
	 * ��� activity
	 * 
	 * @param activity
	 */
	public static void AddAty(Activity activity) {
		list.add(activity);
	}

	/**
	 * �Ƴ� activity
	 */
	public static void FinishAty() {
		for (int i = 0; i < list.size(); i++) {
			list.get(i).finish();
		}
	}

	/**
	 * �ж��Ƿ�ɽ����ɼ�������
	 * 
	 * @param map
	 *            ��������map����
	 * @param type
	 *            map �� key�����磺��������mapΪdata����type���ǽ�data������ݽ�����list���ϵ�key
	 * @return
	 */
	public static boolean IsList(Map<String, String> map, String type) {

		if (map.get(type) != null) {
			if (!map.get(type).equals("") && !map.get(type).equals("null") && !map.get(type).equals("[]")
					&& map.get(type) != null) {
				return true;
			}
		}
		return false;

	}

	/**
	 * ��ȡ��ǰApp���Ի���
	 * 
	 * @param context
	 * 
	 *            ����ֵ ueӢ�ģ�cn ����
	 * 
	 * @return
	 */
	public static String getLanguage(Context context) {
		String lan = null;
		SharedPreferences sp = context.getSharedPreferences("test", Activity.MODE_APPEND);
		lan = sp.getString("language", "cn");
		return lan;
	}

	/**
	 * 
	 * @Title: getPort @Description(����): ���ظۿ����� @param(����): @param
	 * context @param(����): @return @return(����ֵ)�� String @throws
	 */
	public static String getPort(Context context) {
		String port = null;
		SharedPreferences sp = context.getSharedPreferences("test", Activity.MODE_APPEND);
		port = sp.getString("port_name", "");
		return port;
	}

	/**
	 * 
	 * @Title: getPort @Description(����): ����keyƥ�����Ϣ @param(����): @param
	 * context @param(����): @return @return(����ֵ)�� String @throws
	 */
	public static String getInfo(Context context, String key) {
		String port = null;
		SharedPreferences sp = context.getSharedPreferences("test", Activity.MODE_APPEND);
		port = sp.getString(key, "");
		return port;
	}

}
